package com.hmall.item.web;


import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    @GetMapping("/list")
    public PageDTO<Item> list(@RequestParam(value = "page") long page, @RequestParam(value = "size") long size){
        return itemService.selectpage(page, size);

    }

    @GetMapping("/{id}")
    public Item selectById(@PathVariable long id){
        return itemService.getById(id);
    }

    @PostMapping
    public boolean save(@RequestBody Item item){
        item.setCreateTime(new Date());
        return itemService.save(item);
    }

    @PutMapping("/status/{id}/{status}")
    public boolean updateStatus(@PathVariable long id,@PathVariable int status){
        itemService.updateStatus(id,status);
        return true;
    }

    @PutMapping
    public boolean updateitem(@RequestBody Item item){
        item.setUpdateTime(new Date());
        return itemService.updateById(item);
    }

    @DeleteMapping("/{id}")
    public boolean deleteById(@PathVariable long id){
        return itemService.removeById(id);
    }
}
